import { Jieba } from '@node-rs/jieba';
import { dict } from '@node-rs/jieba/dict';

const setupJieba = () => {
    const jieba = Jieba.withDict(dict);
    // const tokens = await getAllBlocks();
    // const bufferArr = Buffer.from(tokens.join('\n'), 'utf-8');
    // jieba.loadDict(bufferArr);
    return jieba;
};

/** @type {Jieba} */
export const jieba = globalThis.jieba || setupJieba();

// nextjs hot reload 将会创建多个实例。
if (process.env.NODE_ENV === 'development') globalThis.jieba = jieba;
